import React from "react";
import Layout from "./layout";
import { Routes, Route, Navigate, useSearchParams } from "react-router-dom";
import Login from "@/views/login/Index";

import { useSelector } from "react-redux";

export default function App() {
  //获取redux里的状态
  const LoginState = useSelector((state) => state.admin.LoginState);

  const [params] = useSearchParams();
  let url = params.get("r");
  url = url ? url : "/";

  return (
    <Routes>
      <Route
        path="/Login"
        element={LoginState ? <Navigate to={url} /> : <Login />}
      />

      <Route
        path="/*"
        element={LoginState ? <Layout /> : <Navigate to="/Login" />}
      />
    </Routes>
  );
}
